<?php
/**
 * Created by littleU.
 * User: littleU
 * Date: 2021-01-29
 * Time: 11:29
 */

namespace app\api\controller\v1\cms;


use app\api\controller\BaseController;
use app\api\service\Product as ProductService;
use app\api\service\ProductCategory as ProductCategoryService;
use app\api\service\ProductAppendix as ProductAppendixService;
use app\api\service\ProductComment as ProductCommentService;

class Product extends BaseController
{
    public function getProductCategoryByCondition()
    {
        $data = input('post.');
        $result = (new ProductCategoryService())->getProductCategoryByCondition($data);
        return $result;
    }

    public function setProductCategory()
    {
        if(request()->isPost())
        {
            $data = input('post.');
            $result = ProductCategoryService::setProductCategory($data);
            return $result;
        }
        else
        {
            return json([
                'code' => config('code.success'),
                'msg'  => '请求类型错误'
            ]);
        }
    }

    public function editProductCategory()
    {
        if(request()->isPost())
        {
            $data = input('post.');
            $result = ProductCategoryService::editProductCategory($data);
            return $result;
        }
        else
        {
            return json([
                'code' => config('code.success'),
                'msg'  => '请求类型错误'
            ]);
        }
    }

    public function getNormalProductCategoryList()
    {
        return ProductCategoryService::getNormalList();
    }

    public function getProductByCondition()
    {
        $data = input('post.');
        $result = (new ProductService())->getProductByCondition($data);
        return $result;
    }

    public function getSkuByCode()
    {
        $code = input('param.')['code'];
        $result = ProductService::getSkuByCode($code);
        return $result;
    }

    public function getPropertyByCode()
    {
        $code = input('param.')['code'];
        $result = ProductService::getPropertyByCode($code);
        return $result;
    }

    public function setProduct()
    {
        $data = input('post.');
        $result = (new ProductService())->setProduct($data);
        return $result;
    }

    public function setProductStatus()
    {
        $data = input('post.');
        $result = ProductService::setProductStatus($data);
        return $result;
    }

    public function setProductSku()
    {
        $data = input('post.');
        $result = ProductService::setProductSku($data);
        return $result;
    }

    public function setProductSkuStock()
    {
        $data = input('post.');
        $result = ProductService::setProductSkuStock($data);
        return $result;
    }

    public function setProductProperty()
    {
        $data = input('post.');
        $result = ProductService::setProductProperty($data);
        return $result;
    }


    public function getNormalProductAppendixList()
    {
        return ProductAppendixService::getNormalList();
    }

    public function setProductAppendix()
    {
        if(request()->isPost())
        {
            $data = input('post.');
            $result = ProductAppendixService::setProductAppendix($data);
            return $result;
        }
        else
        {
            return json([
                'code' => config('code.success'),
                'msg'  => '请求类型错误'
            ]);
        }
    }

    public function getProductCommentByCondition()
    {
        $data = input('post.');
        $result = (new ProductCommentService())->getProductCommentByCondition($data);
        return $result;
    }

    public function setProductComment()
    {
        if(request()->isPost())
        {
            $data = input('post.');
            $result = ProductCommentService::setProductComment($data);
            return $result;
        }
        else
        {
            return json([
                'code' => config('code.success'),
                'msg'  => '请求类型错误'
            ]);
        }
    }
}